<template>
   <div class="app-container">
      <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
         <!-- <el-form-item label="公告标题" prop="noticeTitle">
            <el-input
               v-model="queryParams.noticeTitle"
               placeholder="请输入公告标题"
               clearable
               style="width: 200px"
               @keyup.enter="handleQuery"
            />
         </el-form-item> -->
         <el-form-item label="反馈类型" prop="feedbackType">
            <el-select v-model="queryParams.feedbackType" placeholder="反馈类型" clearable style="width: 200px">
               <el-option
                  v-for="dict in dict.type.feedback_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
               />
            </el-select>
         </el-form-item>
         <el-form-item label="是否已处理" prop="dealFlag">
            <el-select v-model="queryParams.dealFlag" placeholder="是否已处理" clearable style="width: 200px">
               <el-option
                  v-for="dict in dict.type.is_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
               />
            </el-select>
         </el-form-item>
         <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
         </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
         <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
         <!-- <el-table-column type="selection" width="55" align="center" /> -->
         <el-table-column label="序号" align="center" prop="id" width="100" />
         <el-table-column label="反馈用户名称" align="center" prop="nickName" :show-overflow-tooltip="true" />
         <el-table-column label="联系方式" align="center" prop="phone" show-overflow-tooltip />
         <el-table-column label="内容" align="center" prop="content" show-overflow-tooltip />
         <el-table-column label="处理人名称" align="center" prop="dealNickName" show-overflow-tooltip />
         <el-table-column label="处理结果" align="center" prop="dealResult" show-overflow-tooltip />
         <el-table-column label="反馈类型" align="center" prop="feedbackType" >
            <template slot-scope="{row}">
               <dict-tag :options="dict.type.feedback_type" :value="row.feedbackType" />
            </template>
         </el-table-column>
         <el-table-column label="是否已处理" align="center" prop="dealFlag" >
            <template slot-scope="{row}">
               <dict-tag :options="dict.type.is_yes_no" :value="row.dealFlag" />
            </template>
         </el-table-column>
         <el-table-column label="创建时间" align="center" prop="createTime" >
            <template slot-scope="{row}">
               <span>{{ row.createTime }}</span>
            </template>
         </el-table-column>
         <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="300px">
            <template slot-scope="{row}">
               <el-button link type="primary" icon="Edit"
               @click="handleDetail(row,'查看详情')">详情</el-button>
               <el-button link type="primary" icon="Edit"
               @click="handleDetail(row,'回复')" v-if="row.dealFlag !== 1" v-hasPermi="['system:userFeedback:edit']" >回复</el-button>
              <el-button link type="primary" icon="Delete"
              @click="handleDelete(row)" v-hasPermi="['system:userFeedback:remove']" >删除</el-button>
            </template>
         </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- 详情弹框 -->
      <el-dialog
        :title="title"
        :visible.sync="open"
        width="70%"
        append-to-body
      >
        <div class="diy-mx-8">
          <el-radio-group v-model="detailCurrent" style="margin-bottom: 30px;">
            <el-radio-button label="tabDetail1">详细信息</el-radio-button>
            <el-radio-button label="tabDetail2">反馈图片</el-radio-button>
          </el-radio-group>
          <div v-show="detailCurrent == 'tabDetail1'">
            <el-row class="diy-text-sm diy-leading-10" :gutter="10" v-if="detail">
              <el-col :span="24" >
                <div class="flex_hcneter" style="height: 40px;font-weight: bold;font-size: 24px;">
                  	基础信息
                </div>
              </el-col>
              <el-col :span="12">
                <div class="flex_hcneter" style="height: 40px;">
                  <div class="dian_svg"></div>
                  反馈用户名称：{{ detail.nickName }}
                </div>
              </el-col>
              <el-col :span="12">
                <div class="flex_hcneter" style="height: 40px;">
                  <div class="dian_svg"></div>
                  联系方式：{{ detail.phone }}
                </div>
              </el-col>
              <el-col :span="12" v-if="detail.feedbackType == 5">
                <div class="flex_hcneter" style="height: 40px;">
                  <div class="dian_svg"></div>
                  充电终端名称：{{ detail.pileName }}
                </div>
              </el-col>
              <el-col :span="12"  v-if="detail.feedbackType == 5">
                <div class="flex_hcneter" style="height: 40px;">
                  <div class="dian_svg"></div>
                  充电终端编码：{{ detail.pileCode }}
                </div>
              </el-col>
              <el-col :span="12" v-if="detail.feedbackType == 6">
                <div class="flex_hcneter" style="height: 40px;">
                  <div class="dian_svg"></div>
                  电站名称：{{ detail.stationName }}
                </div>
              </el-col>
              <el-col :span="12">
                <div class="flex_hcneter" style="height: 40px;">
                  <div class="dian_svg"></div>
                  反馈类型：<dict-tag :options="dict.type.feedback_type" :value="detail.feedbackType"/>
                </div>
              </el-col>
              <el-col :span="12">
                <div class="flex_hcneter" style="height: 40px;">
                  <div class="dian_svg"></div>
                  反馈时间：{{ detail.createTime }}
                </div>
              </el-col>
              <el-col :span="12">
                <div class="flex_hcneter diy-items-top "  style="height: 40px;">
                  <div class="diy-w-2 diy-h-2 diy-mr-3.5 diy-ml-2">
                    <div class="dian_svg"></div>
                  </div>
                  <div class="diy-leading-7 diy-mt-1">反馈信息：{{ detail.content }}</div>
                </div>
              </el-col>
              <div v-if="detail.feedbackType == 4 && detail.orderVo">
                <el-col :span="24" >
                  <div class="flex_hcneter" style="height: 40px;font-weight: bold;font-size: 24px;">
                    	订单信息
                  </div>
                </el-col>
                <el-col :span="12" >
                  <div class="flex_hcneter" style="height: 40px;">
                    <div class="dian_svg"></div>
                    	订单号：{{ detail.orderVo.orderCode }}
                  </div>
                </el-col>
                <el-col :span="12" >
                  <div class="flex_hcneter" style="height: 40px;">
                    <div class="dian_svg"></div>
                    	终端编号：{{ detail.orderVo.pileCode }}
                  </div>
                </el-col>
                <el-col :span="12" >
                  <div class="flex_hcneter" style="height: 40px;">
                    <div class="dian_svg"></div>
                    	充电通道：{{ detail.orderVo.port }}
                  </div>
                </el-col>
                <el-col :span="12" >
                  <div class="flex_hcneter" style="height: 40px;">
                    <div class="dian_svg"></div>
                    	充电时间(分钟)：{{ detail.orderVo.chargingMinute }}
                  </div>
                </el-col>
                <el-col :span="12" >
                  <div class="flex_hcneter" style="height: 40px;">
                    <div class="dian_svg"></div>
                    	充电电量(千瓦)：{{ detail.orderVo.electricQuantity }}
                  </div>
                </el-col>
                <el-col :span="12" >
                  <div class="flex_hcneter" style="height: 40px;">
                    <div class="dian_svg"></div>
                    	电费：{{ detail.orderVo.electricityAmount }}
                  </div>
                </el-col>
                <el-col :span="12" >
                  <div class="flex_hcneter" style="height: 40px;">
                    <div class="dian_svg"></div>
                    	服务费：{{ detail.orderVo.serviceAmount }}
                  </div>
                </el-col>
                <el-col :span="12" >
                  <div class="flex_hcneter" style="height: 40px;">
                    <div class="dian_svg"></div>
                    	充电总费用：{{ detail.orderVo.totalAmount }}
                  </div>
                </el-col>
                <el-col :span="12" >
                  <div class="flex_hcneter" style="height: 40px;">
                    <div class="dian_svg"></div>
                    	实付金额：{{ detail.orderVo.actualAmount }}
                  </div>
                </el-col>
                <el-col :span="12" >
                  <div class="flex_hcneter" style="height: 40px;">
                    <div class="dian_svg"></div>
                    	开始时间：{{ detail.orderVo.startTime }}
                  </div>
                </el-col>
                <el-col :span="12" >
                  <div class="flex_hcneter" style="height: 40px;">
                    <div class="dian_svg"></div>
                    	结束时间：{{ detail.orderVo.endTime }}
                  </div>
                </el-col>
              </div>
              <el-col :span="24" >
                <div class="flex_hcneter" style="height: 40px;font-weight: bold;font-size: 24px;">
                  	处理信息
                </div>
              </el-col>
              <el-col :span="12" v-if="detail.dealFlag === 1">
                <div class="flex_hcneter" style="height: 40px;">
                  <div class="dian_svg"></div>
                  处理人名称：{{ detail.dealNickName }}
                </div>
              </el-col>
              <el-col :span="12" v-if="detail.dealFlag === 1">
                <div class="flex_hcneter" style="height: 40px;">
                  <div class="dian_svg"></div>
                  处理时间：{{ detail.dealTime }}
                </div>
              </el-col>
              <el-col :span="24"  v-if="detail.dealFlag === 1">
                <div class="flex_hcneter diy-items-top" style="height: 40px;">
                  <div class="diy-w-2 diy-h-2 diy-mr-3.5 diy-ml-2">
                    <div class="dian_svg"></div>
                  </div>
                  <div class="diy-leading-7 diy-mt-1">处理结果：{{ detail.dealResult }}</div>
                </div>
              </el-col>
              <el-col :span="24" v-if="detail.dealFlag !== 1 && title == '回复'">
                <div class="diy-mx-2 diy-mt-2.5">
                  <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                    <el-form-item label="回复内容" prop="dealResult">
                      <el-input v-model="form.dealResult" type="textarea" :maxlength="250" :rows="6" placeholder="请输入回复内容" />
                    </el-form-item>
                  </el-form>
                </div>
              </el-col>
            </el-row>
          </div>
          <div v-show="detailCurrent == 'tabDetail2'">
            <div v-if="detail">
              <div v-if="detail.feedbackImg.length > 0">
                <el-carousel indicator-position="outside" height="500px">
                  <el-carousel-item v-for="(item,index) in detail.feedbackImg" :key="index">
                    <el-image v-if="item" :src="item"  class="diy-h-full" :preview-src-list="detail.feedbackImg"></el-image>
                  </el-carousel-item>
                </el-carousel>
              </div>
              <div v-else>
                <el-empty description="暂无图片"></el-empty>
              </div>
            </div>
          </div>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm" v-if="detail.dealFlag !== 1 && title == '回复'">回复</el-button>
          <el-button @click="cancel">关 闭</el-button>
        </div>
      </el-dialog>

   </div>
</template>

<script>
import { listOpinionFeedback, getOpinionFeedback,  handleOpinionFeedback,delOpinionFeedback } from "@/api/config/feedback";
export default {
  name: 'Feedback',
  dicts: ['feedback_type','is_yes_no','chargin_order_paytype'],
  components: {  },
  data() {
    return {
      //切换
      detailCurrent: 'tabDetail1',
      form: {},// 表单参数
      detail:{feedbackImg:[]},// 表单参数
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      queryParams: {// 查询参数
        pageNum: 1,
        pageSize: 10,
        feedbackType:null,
        dealFlag:null,
      },
      // 总条数
      total: 0,
      rules: {
        dealResult: [{ required: true, message: "回复内容不能为空", trigger: "blur" }],
      },
      list:[],//页面数据
    };
  },
  mounted(){
    this.getList()
  },
  methods: {
    handleDetail(e,title){//详情点击
      this.detailCurrent = 'tabDetail1'
      this.open = true
      this.title = title
      getOpinionFeedback(e.id).then(response => {
        let data = response.data || {}
        let imgPaths = data.imgPaths || ''
        this.form = {}
        this.form.id = data.id
        this.detail = {...data,feedbackImg:imgPaths ? imgPaths.split(',') : []}
        console.log('this.detail',this.detail)
      });
    },
    getList() {
      this.loading = true;
      listOpinionFeedback(this.queryParams).then(response => {
        let rows = response.rows || [];
        this.list = rows.map(item=>{
          let imgPaths = item.imgPaths || ''
          let imgPathList = []
          if(imgPaths) imgPathList = imgPaths.split(',')
          return {
            ...item,
            imgPathList,
          }
        })
        this.total = response.total || 0;
        this.loading = false;
      });
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let form = {...this.form}
          handleOpinionFeedback(form).then(response => {
            this.$modal.msgSuccess("操作成功")
            this.open = false;
            this.getList();
          });
        }
      });
    },
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryRef");
      this.handleQuery();
    },
    handleDelete(row) {//删除
      const del_ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除编号为"' + del_ids + '"的数据项？').then(function() {
        return delOpinionFeedback(del_ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
  }
}
</script>
<style lang="scss">
  .dian_svg{
    width: 7.5px;
    height: 7.5px;
    vertical-align: -0.15em;
    fill: currentColor;margin-left: 0.5rem;margin-right: 0.25rem;
    overflow: hidden;font-size: 20px;background-color: #409EFF;
    border-radius: 50%;
  }
</style>
